package com.TradeQuery;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.os.AsyncTask;
import android.os.Message;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;

public class SoapAsyncTask extends AsyncTask<SoapSerializationEnvelope, ProgressBar, SoapObject> {
        
	private String sServiceURL = "http://otbwsdl.wanjuz.com/WebService.asmx?wsdl";
   
	ProgressBar te=null;
    
	
    public SoapAsyncTask(ProgressBar te) {
        super();
        this.te = te;
    }



        @Override
        protected SoapObject doInBackground(SoapSerializationEnvelope...  params) {
            // TODO Auto-generated method stub
        	SoapObject result ;
        	result = null ;
        	
        	
        	
        	/*
           	String methodName = "QueryTrade";
           	SoapObject request = new SoapObject("http://TBSHZYWSDL.org/",methodName);
           	request.addProperty("sAppSign","TradeQuery2012");
           	request.addProperty("sParmName","mobile");
           	request.addProperty("sParmValue", "18999516366");//strTempMobile);
           	SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
           	envelope.bodyOut = request;
         
           	envelope.dotNet = true ;
           	*/
        	SoapSerializationEnvelope envelope =  params[0] ;
           	HttpTransportSE ht = new HttpTransportSE(sServiceURL);
           	
           	int nTry = 0 ;
           	while( nTry < 3)
           	{
           	try{
           		ht.call(null, envelope);
           		
           		
           		if(envelope.getResponse()!=null){           			
           			result  = (SoapObject) envelope.getResponse();
           			break ;
           		}
           		
           		Thread.sleep(2000);
              	} catch(Exception e){ 
              		e.printStackTrace();
              	}
           	
           	nTry ++ ;
           	
           	

           	}
           			
            
            return result;
        }

        @Override    
        protected void onPostExecute(SoapObject result) {    
            Message msg = new Message();  
            msg.what = 1;  
            msg.obj = result;  
            handleMessage(msg);  
            
            te.setVisibility( ProgressBar.INVISIBLE );
        }    
          
        public boolean handleMessage(Message msg) {  
            // TODO Auto-generated method stub   
            return false;  
        }  
          

        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub\
            System.out.println("pretExecute------");
            te.setVisibility( ProgressBar.VISIBLE );
            super.onPreExecute();
        }

        /* (non-Javadoc)
         * @see android.os.AsyncTask#onProgressUpdate(Progress[])
         */
        @Override
        protected void onProgressUpdate(ProgressBar... values) {
            // TODO Auto-generated method stub
            te.setVisibility( ProgressBar.VISIBLE );
            super.onProgressUpdate(values);
        }
        
    }

